//
//  TSTeamInfoHeaderView.swift
//  TSProfitProject
//
//  Created by TmmmS on 2019/11/24.
//  Copyright © 2019 TMS. All rights reserved.
//

import UIKit

class TSTeamInfoHeaderView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        configViews()
        drawLine()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

extension TSTeamInfoHeaderView {
    
    func configViews() {
        
        let titleContainer = UIView.init()
        titleContainer.backgroundColor = WHITE_COLOR
        addSubview(titleContainer)
        titleContainer.snp.makeConstraints { (make) in
            make.left.top.right.equalToSuperview()
            make.height.equalTo(30)
        }
        
        let titleLabel = UILabel.init()
        titleLabel.text = "我的信息"
        titleLabel.font = UIFont.systemFont(ofSize: 16, weight: .medium)
        titleContainer.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(15)
        }
        
        let itemContainer = UIView.init()
        itemContainer.backgroundColor = WHITE_COLOR
        addSubview(itemContainer)
        itemContainer.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.top.equalTo(titleContainer.snp.bottom)
            make.height.equalTo(titleContainer)
        }
        
        let userItem = TSTeamItemView.init()
        userItem.setupItem(value: "用户名/ID")
        itemContainer.addSubview(userItem)
        userItem.snp.makeConstraints { (make) in
            make.left.centerY.equalToSuperview()
            make.width.equalToSuperview().multipliedBy(0.3)
        }
        
        let levelItem = TSTeamItemView.init()
        levelItem.setupItem(value: "级别")
        itemContainer.addSubview(levelItem)
        levelItem.snp.makeConstraints { (make) in
            make.left.equalTo(userItem.snp.right)
            make.centerY.equalTo(userItem)
            make.width.equalToSuperview().multipliedBy(0.2)
        }
        
        let tradeItem = TSTeamItemView.init()
        tradeItem.setupItem(value: "总流水(万)")
        itemContainer.addSubview(tradeItem)
        tradeItem.snp.makeConstraints { (make) in
            make.left.equalTo(levelItem.snp.right)
            make.centerY.equalTo(userItem)
            make.width.equalToSuperview().multipliedBy(0.3)
        }
        
        let peopleItem = TSTeamItemView.init()
        peopleItem.setupItem(value: "人数")
        itemContainer.addSubview(peopleItem)
        peopleItem.snp.makeConstraints { (make) in
            make.left.equalTo(tradeItem.snp.right)
            make.centerY.equalTo(userItem)
            make.right.equalToSuperview()
        }
    }
    
    func drawLine() {
        
        let path = UIBezierPath.init()
        path.move(to: CGPoint.zero)
        path.addLine(to: CGPoint.init(x: 0, y: self.frame.size.height))
        path.addLine(to: CGPoint.init(x: self.frame.size.width, y: self.frame.size.height))
        path.addLine(to: CGPoint.init(x: self.frame.size.width, y: 0))
        path.addLine(to: CGPoint.zero)
        
        path.move(to: CGPoint.init(x: 0, y: self.frame.size.height*0.5))
        path.addLine(to: CGPoint.init(x: self.frame.size.width, y: self.frame.size.height*0.5))
        
        path.move(to: CGPoint.init(x: self.frame.size.width*0.3, y: self.frame.size.height*0.5))
        path.addLine(to: CGPoint.init(x: self.frame.size.width*0.3, y: self.frame.size.height))
        
        path.move(to: CGPoint.init(x: self.frame.size.width*0.5, y: self.frame.size.height*0.5))
        path.addLine(to: CGPoint.init(x: self.frame.size.width*0.5, y: self.frame.size.height))
        
        path.move(to: CGPoint.init(x: self.frame.size.width*0.8, y: self.frame.size.height*0.5))
        path.addLine(to: CGPoint.init(x: self.frame.size.width*0.8, y: self.frame.size.height))
        
        path.lineWidth = 1
        
        let shapeLayer = CAShapeLayer()
        shapeLayer.frame = self.frame
        shapeLayer.fillColor = UIColor.clear.cgColor
        shapeLayer.lineWidth = 1
        shapeLayer.strokeColor = UIColor.hexadecimalColor(hexadecimal: "#DDDDDD").cgColor

        shapeLayer.path = path.cgPath
        shapeLayer.position = self.center
        self.layer.addSublayer(shapeLayer)
    }
}

